#include <compilation/task/Phi.h>

#include <compilation/instruction/Expression.h>
#include <compilation/instruction/Instruction.h>


namespace compilation
{


bool
PhiIsBefore::operator()(
    VirtualExpression* fst,
    VirtualExpression* snd) const
{
  if (fst->type() == snd->type())
  {
    if (fst->type() == ExpressionType::TLocalVariable)
      return (expression_cast<TLocalVariable>(fst)->getGlobalIndex() <
              expression_cast<TLocalVariable>(snd)->getGlobalIndex());

    if (fst->type() == ExpressionType::TParameter)
      return (expression_cast<TParameter>(fst)->getIndex() <
              expression_cast<TParameter>(snd)->getIndex());

    return (expression_cast<TGlobalVariable>(fst)->getIndex() <
            expression_cast<TGlobalVariable>(snd)->getIndex());
  }

  return fst->type() > snd->type();
}


LocalVariableExpression
PhiLabelResult::getAfterScopeLocalVariable(void) const
{ return LocalVariableExpression(std::string(), m_scope.count(), m_scope); }


} // compilation
